package com.ruoyi.system.service;

import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.helper.LoginHelper;
import org.jeecg.modules.jmreport.api.JmReportTokenServiceI;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 类作用描述
 *
 * @author pengju.liao
 * @date 2022/3/27
 */
@Component
public class JimuReportTokenService implements JmReportTokenServiceI {

    @Override
    public String getToken(HttpServletRequest request) {
        return request.getParameter("token");
    }

    @Override
    public String getUsername(String s) {
        LoginUser loginUser = LoginHelper.getLoginUser();
        return loginUser.getUsername();
    }

    @Override
    public Boolean verifyToken(String s) {
        return LoginHelper.getLoginUser()!=null;
    }

    @Override
    public Map<String, Object> getUserInfo(String token) {
        Map<String,Object> paramMap = new HashMap();
        paramMap.put("token", "Bearer "+StpUtil.getTokenSession().getId().replace("token:login:token-session:", ""));
        return paramMap;
    }

}
